#pragma once

#if defined(DEBUG) | defined(_DEBUG)

#include <iostream>

#endif

#include <Windows.h>
#include <string>
#include <sstream>
#include <map>

using namespace std;

#define BUFFERSIZEMAX ((DWORDLONG)4*1024*1024*1024)

#define IO_READ			0xf1
#define IO_WRITE		0xf2	// not supported
#define IO_READWRITE	0xf3

class cFileIO {
private:
	ostringstream error;
	char *error_info;
	
	map<HANDLE, int> handle_access;
	map<HANDLE, char*> handle_buffers;
public:
	cFileIO();
	~cFileIO();
	
	const char* GetErrorInformation(__in_opt DWORD *error_code);
	bool CloseHANDLE(HANDLE hndl);
	void CloseAllHeandles();

	HANDLE OpenFile(__in char *filename, __in int access, __in_opt DWORD *filesize_high, __in_opt DWORD *filesize_low);
	HANDLE CreateMappingOfFile(HANDLE hFile, DWORD filesize_high = 0, DWORD filesize_low = 0);
	char* Map(HANDLE hMapFile, DWORD offset_high, DWORD offset_low, SIZE_T size);
};